package cn.boxiao.bxn.cloud;

import java.io.IOException;

import cn.boxiao.bxn.cloud.util.SSHUtils;

public class SSHTest {
	public static void main(String[] args) {
        try {
        	addRoute("172.16.2.51,172.16.2.52,172.16.0.26");
        } catch (IOException e) {
            e.printStackTrace();
        }
	}
	
	public static void addRoute(String ips) throws IOException{
		String[] ipArray = ips.split(",");
		for(String ipA : ipArray){
			for(String ipB : ipArray){
				if(ipA.equals(ipB)){
					continue;
				}
				System.out.println(ipA + "<===" + ipB);
				SSHUtils nodeA = new SSHUtils(ipA, "root", "123456");
				SSHUtils nodeB = new SSHUtils(ipB, "root", "123456");
				String routeB = nodeB.exec("route|grep docker0");
				if(routeB.length()==0){
					System.out.println(ipB + "route error!");
				}else{
					String ipDocker0 = routeB.split(" ")[0];
					nodeA.exec("route add -net " + ipDocker0 + " netmask 255.255.255.0 gw " + ipB + " && route");
				}
			}
		}
		
	}
}
